package logic

import (
	"svvenus/conf"
	"svvenus/vpub/constants"
	"svvenus/vpub/db/dbm"
	"svvenus/znet/zpb"
	"time"
)

// SchedulePerMinute
// @Description: 玩家分钟
// @receiver player
// @param db
func (player *Player) SchedulePerMinute(db *dbm.MgoSession) {

	player.SaveAuto(db)

	player.VitalityRecovery()
}

// SaveAuto
// @Description: 自动存盘
// @receiver player
func (player *Player) SaveAuto(db *dbm.MgoSession) {
	if constants.SvTime.After(player.TimeSave.Add(time.Minute * 30)) {
		player.Save(db, false)
	}
}

// VitalityRecovery
// @Description: 体力恢复
// @receiver player
func (player *Player) VitalityRecovery() {
	if constants.SvTime.After(player.TimeVitalityRecovery.Add(time.Minute * time.Duration(conf.V玩家体力多少分钟回复一次))) {
		Minutes := int64(constants.SvTime.Sub(player.TimeVitalityRecovery).Minutes())
		if Minutes < 1 {
			Minutes = 1
		}

		valMax := player.VitalityMax()
		val := player.MoneyValue(conf.EMoneyType体力)
		if val < valMax {
			valRecover := Minutes * player.VitalityRecoverValue()
			if valRecover > valMax-val {
				valRecover = valMax - val
			}
			player.MoneyAdd(conf.EMoneyType体力, valRecover, zpb.RecSource_rsSystem)
			player.PushInfoBase()
		}

		player.TimeVitalityRecovery = constants.SvTime.Add(time.Minute * time.Duration(Minutes))
	}
}

// ScheduleOClock0
// @Description: 玩家0点更新
// @receiver player
func (player *Player) ScheduleOClock0() {

}

// ScheduleOClock5
// @Description: 玩家5点更新
// @receiver player
func (player *Player) ScheduleOClock5() {

	//删除过期邮件
	player.MailCheckOverdue()

}
